<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="./js/lodash.min.js"></script>
    <script>
        let students = [
            { id: '1', name: '张三' },
            { id: '2', name: '李四' },
        ]

        const newStudents = _.cloneDeep(students)

        // const newStudents = deepClone(students);





        function deepClone(data) {
            if (Array.isArray(data)) {
                let newArr = [];
                for (let value of data) {
                    newArr.push(deepClone(value))
                }
                return newArr;
            } else if (typeof data === 'object') {
                let newObj = {};
                for (let key in data) {
                    newObj[key] = deepClone(data[key]);
                }
                return newObj;
            }
            return data;
        }


        // const str1 = String(students)

        // const str2 = JSON.stringify(students);
        // const newStudents = JSON.parse(str2);

        // const newStudents = JSON.parse(JSON.stringify(students))

        // let newStudents = [
        //     ...students
        // ]

        students.push({
            id: '3', name: '王五'
        })

        students[0].name = '马冬梅';

        console.log(students, newStudents);

    </script>
</body>

</html>